import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;


//sql.search(sql.login("root", "root9852", url),"SELECT id,name,age,nation,gender,work,academy FROM teacher;");
//sql.del(sql.login("root", "root9852", url), "DELETE FROM teacher WHERE id=111026;");
//sql.update(sql.login("root", "root9852", url), "UPDATE teacher SET id=111025 WHERE name='唐玄宗';");

public class TeacherSystem implements TeacherInterface{

	Scanner scan=new Scanner(System.in);
	//欢迎界面
	public void welcome() {
		System.out.println("********欢迎进入教师管理系统****************");
		System.out.println("\n");
		System.out.println("初始化成功。。。。。。。。。。。。。。。。。。。");
	}
	//退出界面
	public void exit() {
		System.out.println("********感谢使用教师管理系统****************");
	}
	//菜单界面
	public void showMenu() {
		System.out.println("************");
		System.out.println("1.显示所有教师信息");
		System.out.println("2.选择添加教师信息");
		System.out.println("3.学号查找教师信息");
		System.out.println("4.姓名查找教师信息");
		System.out.println("5.选择删除教师信息");
		System.out.println("6.选择修改教师信息");
		System.out.println("7.退出系统");
		System.out.println("************");
	}
	public void showAll(Statement stmt,String sql) {
		try {
			ResultSet rs = stmt.executeQuery(sql);
			while(rs.next()){
				System.out.print("id"+"\t"+"姓名"+"\t"+"年龄"+"\t"+"民族"+"\t"+"性别"+"\t"+"是否在职"+"\t"+"所在院系"+"\t"+"\n");
				System.out.print("------------------------------------------------------"+"\n");
                // 通过字段检索
                int id  = rs.getInt("id");
                String name = rs.getString("name");
                int age = rs.getInt("age");
                String nation = rs.getString("nation");
                String gender = rs.getString("gender");
                String work = rs.getString("work");
                String academy = rs.getString("academy");
                // 输出数据
                System.out.print(id+"\t"+name+"\t"+age+"\t"+nation+"\t"+gender+"\t"+work+"\t"+academy+"\t");
                System.out.print("\n");
			}
		}catch (Exception e) {
			// TODO: handle exception
		}
	}

	public boolean exchangeStu(Statement stmt,String sql) {
		return false;
	}

	@Override
	public void findByid(Statement stmt,String sql) {
		// TODO 自动生成的方法存根
		
	}

	@Override
	public void findByname(Statement stmt,String sql) {
		// TODO 自动生成的方法存根
		try {
			ResultSet rs = stmt.executeQuery(sql);
			
			if(rs.next()){
				System.out.print("id"+"\t"+"姓名"+"\t"+"年龄"+"\t"+"民族"+"\t"+"性别"+"\t"+"是否在职"+"\t"+"所在院系"+"\t"+"\n");
				System.out.print("------------------------------------------------------"+"\n");
                // 通过字段检索
                int id  = rs.getInt("id");
                String name = rs.getString("name");
                int age = rs.getInt("age");
                String nation = rs.getString("nation");
                String gender = rs.getString("gender");
                String work = rs.getString("work");
                String academy = rs.getString("academy");
                // 输出数据
                System.out.print(id+"\t"+name+"\t"+age+"\t"+nation+"\t"+gender+"\t"+work+"\t"+academy+"\t");
                System.out.print("\n");
			}else {
				System.out.print("未查询到相关信息\n");
			}
		}catch (Exception e) {
			// TODO: handle exception
		}
		
	}
	@Override
	public boolean removeStu(Statement stmt,String sql) {
		try {
			stmt.executeUpdate(sql);
		} catch (SQLException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
		return false;
	}
	@Override
	public void addStudent(Statement stmt,String sql) {
		// TODO 自动生成的方法存根
		
	}

}